package com.soup.lab.spring.databind.controller;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Part;
import java.util.Map;

@RestController
@RequestMapping("requestParam")
public class RequestParamController {

    @GetMapping("simple")
    public SimpleModel simpleGet(int a, long b, double c, boolean d, Integer e, Long f, Double g, Boolean h) {
        return new SimpleModel(a, b, c, d, e, f, g, h);
    }

    @GetMapping("map")
    public Map<String, String> simpleMap(@RequestParam Map<String, String> params, Part file) {
        System.out.println(file.getSize());
        return params;
    }

    @GetMapping("map2")
    public Object simpleMap2(ModelMap params) {
        System.out.println(params.getClass());
        System.out.println(params);
        return "ok";
    }

    @GetMapping("map3")
    public Object simpleMap3(Map<String, Object> params) {
        System.out.println(params.getClass());
        System.out.println(params);
        return params;
    }

    @ModelAttribute("a")
    public SimpleModel simpleModel() {
        SimpleModel simpleModel = new SimpleModel();
        simpleModel.setA(1);
        simpleModel.setB(2L);
        return simpleModel;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    private static class SimpleModel {
        private int a;
        private long b;
        private double c;
        private boolean d;
        private Integer e;
        private Long f;
        private Double g;
        private Boolean h;
    }



}
